package com.tianqu.tms.www.cardect.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.cardect.actionform.CarAllocateTopListActionForm;
/**
 * 待确认列表页提交中转Action
 * 
 * @author tianshifu
 *
 */
public class CarWaitConfirmTopListDispatchAction extends TmsAction {
	private Logger logger = Logger.getLogger(CarWaitConfirmTopListDispatchAction.class);//log
	private static final String ALLOCATEID = "carSerial";//定义页面checkbox的property
	private static final String ADDMODE    = "addModel";//转录入模式 1 人工 2 ipad 6检测完了

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		String actionForward = "";//页面跳转参数
		
		CarAllocateTopListActionForm allocateForm = (CarAllocateTopListActionForm)form;
		
		//获取页面checkbox选中项
		String[] checkbox = request.getParameterValues(ALLOCATEID);
		
		//这个地方需要对checkbox进行处理 去掉“false”
		String checkValue = "";
		String checkVV = "";
		if(checkbox!=null)
		{
			for(int i=0;i<checkbox.length;i++)
			{
				checkValue = checkbox[i];
				if(!checkValue.equals("false"))
				{
					checkVV += checkValue+",";
				}
			}
		}
		
		
		if(checkbox == null || "".equals(checkVV))
		{
			//说明没有选中，向前台打出提示
			setErrorsToRequest(request, TmsConstants.IA001 ,null);
			return mapping.getInputForward();
		}
		
		uc.setAttribute(ALLOCATEID, checkbox);//将选中车辆ID数组放到uc中在下个action中处理
		
		if(allocateForm.getDetectOverConfirmButton()!=null)// 确认按钮
		{
			//确认
			actionForward = "detectOverConfirm";
			uc.removeAttribute(ADDMODE);
			uc.setAttribute(ADDMODE, "6");//检测完了
		}
		
		if(allocateForm.getToPersonConfirmButton()!=null)//人工重新检测
		{
			//人工重新检测
			actionForward = "toReAddConfirm";
			uc.removeAttribute(ADDMODE);
			uc.setAttribute(ADDMODE, "3");//人工
		}
		if(allocateForm.getToIpadConfirmButton()!=null)// IPAD重新检测
		{
			// IPAD重新检测
			actionForward = "toReAddConfirm";
			uc.removeAttribute(ADDMODE);
			uc.setAttribute(ADDMODE, "2");//ipad
		}

		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(actionForward);
	}

}
